package com.haolijun.eecms.controller;

import cn.hutool.json.JSONUtil;
import com.haolijun.eecms.common.R;
import com.haolijun.eecms.controller.form.InsertNoticeCommentForm;
import com.haolijun.eecms.entity.TbNoticeComment;
import com.haolijun.eecms.service.NoticeCommentService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @ClassName NoticeCommentController
 * @Description TODO
 * @Author hljstart
 * @Date 2023/3/11 21:39
 * @Version 1.0
 */
@Tag(name = "NoticeCommentController",description = "公告评论Web接口")
@RestController
@RequestMapping("/noticeComment")
@Slf4j
public class NoticeCommentController {

    @Autowired
    private NoticeCommentService noticeCommentService;

    @PostMapping("/insert")
    public R insert(@Valid @RequestBody InsertNoticeCommentForm form){
        TbNoticeComment noticeComment = JSONUtil.parse(form).toBean(TbNoticeComment.class);
        int rows = noticeCommentService.insert(noticeComment);
        return rows > 0 ? R.ok() : R.error();
    }
}
